#!/usr/bin/env /usr/local/python3
# -*- coding: utf-8 -*-

import cv2
import face_recognition   # cmake dlib face_recognition

"""
人脸识别2及对比匹配，
"""

__author__ = "hubert"


if __name__ == '__main__':
    cap = cv2.VideoCapture("/Users/hubert/Downloads/视频测试/part2.ts")  # rtsp://admin:admin@192.168.2.64:554//Streaming/Channels/1



    while cap.isOpened():
        retval, image = cap.read()
        if not retval:  # 读完视频后falg返回False
            print("播放完毕，退出")
            break
        print("时间：", cap.get(0))  # cap.get(0) 视频文件的当前位置（播放）以毫秒为单位
        # """
        if retval:
            # 可调整视频窗大小
            # cv2.namedWindow("Video_Frame", cv2.WINDOW_NORMAL)
            # 设置视频窗默认大小
            # cv2.resizeWindow("Video_Frame", 640, 480);
            image = cv2.resize(image, None, fx=0.5, fy=0.5)
            # 灰度处理
            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
            # 多个尺度空间进行人脸检测   返回检测到的人脸区域坐标信息


            face_locations = face_recognition.face_locations(image)



            # 绘制矩形和圆形检测人脸
            for x, y, w, h in face_locations:
                cv2.rectangle(image, pt1=(x, y), pt2=(x + w, y + h), color=[0, 0, 255], thickness=2)
                cv2.circle(image, center=(x + w // 2, y + h // 2), radius=w // 2, color=[0, 255, 0], thickness=2)

            # 显示视频窗
            cv2.imshow("Video_Frame", image)
        # """
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cv2.destroyAllWindows()
    cap.release()





